package com.fzkj.juc.forkjoin.entity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * @ description
 * @ author yaya
 * @ since 2024/9/5
 */
public class UserContext {

    public static final Map<Integer, User> userMap = new HashMap<>(10000);

    static {
        for (int i = 0; i < 10000; i++) {
            User user = new User(i, "name" + i, "identity--" + i);
            if (i % 9 == 0) {
                user.setUserId(i / 9);
            }
            userMap.put(user.getUserId(), user);
        }
    }

    public static boolean isExist(int userId){
        return userMap.containsKey(userId);
    }

    public static boolean isExist(List<Integer> ids) {
        Optional<Boolean> first = ids.stream().map(UserContext::isExist).filter(b -> !b).findFirst();
        if (first.isPresent())return first.get();
        return true;
    }

}
